<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        li {
            list-style: none;
            float: left;
            width: 130px;
            height: 30px;
            line-height: 30px;
            text-align: center;
        }
        li.ac {
            background-color: #ccc;
        }
        img {
            width: 400px;
            height: 300px;
        }
        #box {
            width: 400px;
            margin: 0 auto;
        }
        ul {
            border: 1px solid #999;
            height: 30px;
        }
        .wrap div {
            display: none;
        }
        .wrap div.ac {
            display: block;
        }
    </style>
    <script>
        window.onload = function(){
            class Tab {
                constructor(selector){
                    this.box = document.querySelector(selector);
                    this.btns = document.querySelectorAll('ul li');
                    this.imgs = document.querySelectorAll('.wrap div')
                    this.blindEvents();
                }
                blindEvents (){
                    this.btns.forEach((btn,index) => {
                        btn.onclick = () => {
                            this.changeImg(index);
                        }
                    })
                }
                changeImg(index){
                    for(var i =0; i < this.btns.length;i++){
                        this.btns[i].classList.remove('ac');
                        this.imgs[i].classList.remove('ac');
                    }
                    this.btns[index].classList.add('ac');
                    this.imgs[index].classList.add('ac');
                }
            }
            new Tab('#box')
        }
    </script>
</head>
<body>
    <div id="box">
        <ul>
            <li class="ac">item1</li>
            <li>item2</li>
            <li>item3</li>
        </ul>
        <div class="wrap">
            <div class="ac"><img src="http://article-fd.zol-img.com.cn/t_s640x2000/g5/M00/00/08/ChMkJ1q0U2OIWvSnAAIJG_QGnWEAAm8ugOLHNsAAgkz683.jpg" alt=""></div>
            <div><img src="http://attach.bbs.miui.com/forum/201812/16/144625kvf5fbeep6e6peez.jpg" alt=""></div>
            <div><img src="http://5b0988e595225.cdn.sohucs.com/images/20170924/5c68569c9a584a618a517bfdeafc844c.jpeg" alt=""></div>
        </div>
    </div>
</body>
</html>